package com.flower.algorithm.stack;

/**
 * @ClassName StackArray
 * @Description 顺序栈数据结构实现
 * @Author 吃麻椒的花酱
 * @Date 2021/11/26 21:30
 * @Version 1.0
 */
public class StackArray {
    private int top;
    private int[] stack;
    private int maxSize;

    // 初始化顺序栈
    public StackArray(int maxSize){
        this.top=-1;
        this.stack = new int[maxSize];
        this.maxSize = maxSize;
    }

    public  boolean isEmpty(){
        return top == -1;
    }

    public boolean isFull(){
        return  top==maxSize-1;
    }

    public void push(int element){
        if(isFull()){

            throw new RuntimeException("栈已满");
        }
        if(element>10) {
            return;
        }

        top++;
        stack[top]=element;
    }
    public int pop() {
        if(isEmpty()) {
            throw new RuntimeException("栈已空");
        }

        return stack[top--];
    }


}
